layui.use(['layer','element','jquery'],function() {
    layer = layui.layer;
    element = layui.element;
    $ = layui.jquery;

    getDate();
    getSysStatus();
    function getDate(){
        //获取当前时间
        var date = new Date();
        //格式化为本地时间格式
        var date1 = date.toLocaleString();
        //获取div
        var div1 = document.getElementById("time");
        //将时间写入div
        div1.innerHTML = date1;
    }
    //使用定时器每秒向div写入当前时间
    setInterval(getDate,1000);

    function getSysStatus() {
        $.get(contextRoot+"gateway/status", function(result){
            //遍历
            showStatus("gateway",result);
        });

        $.get(contextRoot+"eureka/status", function(result){
            //遍历
            showStatus("eureka",result);
        });
    }

    function showStatus(id,data) {
        $("#"+id).find("td[name]").each(function () {
            $(this).text(data[$(this).attr("name")])
        })
    }

    $("#monitor").click(function () {
        layer.open({
            type: 2,
            title:'实时监控',
            content: contextRoot+"gateway/monitor"
            ,area:['90%','90%']
        });
    })
    $("#log").click(function () {
        layer.open({
            type: 2,
            title:'访问日志',
            content: contextRoot+"gateway/log"
            ,area:['90%','90%']
        });
    })
})

